package com.wjjun.databinding;

import android.databinding.BindingAdapter;
import android.support.annotation.NonNull;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.wjjun.presenter.ViewGroupPresenter;

/**
 * SmartRefreshLayout
 * Created by 67535 on 2018/5/7.
 */
public class SmartRefreshLayoutAdapter {

    @BindingAdapter(value = "onRefresh")
    public static void SmartRefreshLayout(final SmartRefreshLayout smartRefreshLayout, final ViewGroupPresenter viewGroupPresenter) {
        if (viewGroupPresenter == null) {
            return;
        }
        smartRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                viewGroupPresenter.onLoadMore(refreshLayout);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                viewGroupPresenter.onRefresh(refreshLayout);
            }
        });
    }

    @BindingAdapter(value = {"enableRefresh", "enableLoadMore"}, requireAll = false)
    public static void setRefreshEnable(SmartRefreshLayout refreshEnable, boolean enableRefresh, boolean enableLoadMore) {
        refreshEnable.setEnableRefresh(enableRefresh);
        refreshEnable.setEnableLoadMore(enableLoadMore);
    }
}
